package com.madi.company.model;

import com.madi.company.api.Api;
import com.madi.company.api.ApiService;
import com.madi.company.bean.JobAddressEntity;
import com.madi.company.bean.SearchResumeEntity;
import com.madi.company.contract.SearchResumeContract;
import com.madi.company.utils.DnUtil;

import java.util.List;
import java.util.Map;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by 丁宁
 * on 2017/2/14.
 */

public class SearchResumeModel implements SearchResumeContract.Model {
    @Override
    public Observable<SearchResumeEntity> getResumeData(Map<String, String> map) {
        return Api.getInstance().getProxy(ApiService.class).getResumeListData(Api.getCacheControl(),map).map(new Func1<SearchResumeEntity, SearchResumeEntity>() {
            @Override
            public SearchResumeEntity call(SearchResumeEntity entity) {
                List<SearchResumeEntity.RowsBean> mList = entity.getRows();
                List<JobAddressEntity> addressList = DnUtil.getAddressList();
                for (JobAddressEntity bean : addressList) {
                    for (SearchResumeEntity.RowsBean rowsBean : mList) {
                        String city = rowsBean.getLiveCity();
                        if (bean.getCode().equals(city)) {
                            rowsBean.setCityName(bean.getName());
                        }
                    }
                }
                return entity;
            }
        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
    }
}
